package patterns.chain;

import System.Task.Task;

public class CollisionHandler  implements EmergencyHandler {
    private EmergencyHandler nextHandler;

    @Override
    public void setNextHandler(EmergencyHandler nextHandler) {
        this.nextHandler = nextHandler;
    }

    @Override
    public void handleRequest(String emergencyType, Task task, String details) {
        if ("COLLISION_RISK".equals(emergencyType)) {
            System.out.println("[紧急处理] 碰撞风险警报 - 任务: " + task.getTaskId());
            task.addCommand("碰撞风险警报: " + details);

            // 立即停止农机移动
            task.addCommand("已发送紧急停止指令");

            // 标记任务为失败
            task.fail("碰撞风险: " + details);
        } else if (nextHandler != null) {
            nextHandler.handleRequest(emergencyType, task, details);
        }
    }
}
